﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Radiation___IM.Commands
{
    public class Login : ICommand
    {
        private readonly string m_commandkey = "login";

        public Login()
        {
        }

        public string commandKey()
        {
            return m_commandkey;
        }

        public string requiredPermission()
        {
            return "login";
        }

        public void execute(string[] command_parts, Client client)
        {
            if (command_parts.Length > 1 && command_parts[1].Length > 0 && Users.UserManager.Instance[command_parts[1]] != null)
            {
                Users.User user = Users.UserManager.Instance[command_parts[1]];
                if (command_parts.Length > 2 && command_parts[2] == user.Password)
                {
                    Nick.changeNick(command_parts[1], client);
                }
                else
                    MessageExecution.sendData(client, "The password you entered is invalid. Try again.");
                    
            }
            else
                MessageExecution.sendData(client, "The username you provided is too short / does not exist.");
        }
    }
}
